// https://www.acwing.com/problem/content/831/

#include <iostream>
#include <vector>

using namespace std;

constexpr int ARRAY_MAX_SIZE = 100010;
constexpr int END = -1;

struct EasyQueue {
    int nums[ARRAY_MAX_SIZE];
    int start;
    int end;
};

EasyQueue que;


void init() {
    que.start = 0;
    que.end = 1;
    que.nums[0] = END;
    que.nums[1] = END;
}


int main() {
    int n;
    string opt;
    int x;
    init();
    cin>>n;
    while (n-->0) {
        cin>>opt;
        if (opt == "push") {
            cin>>x;
            que.nums[que.end] = x;
            que.end++;
        } else if (opt == "pop") {
            que.start++;
        } else if (opt == "empty") {
            if (que.end - que.start == 1) {
                cout<<"YES"<<endl;
            } else {
                cout<<"NO"<<endl;
            }
        } else if (opt == "query") {
            cout<<que.nums[que.start+1]<<endl;
        }
    }
    return 0;
}
